﻿using MediatR;
using ProduceBasicData.Api.Application.Command.ProductionManage.Technology;
using ProduceBasicData.Domain.WarehouseManage;
using ProduceBasicData.ErrorCode;
using ProduceBasicData.Infrastructure.Interface;

namespace ProduceBasicData.Api.Application.Handler.ProductionManage.Technology
{
    public class GetWareHouseCommandHandler : IRequestHandler<GetWareHouseCommand, ApiResult<List<Warehouse>>>
    {
        private readonly IBaseRespository<Warehouse> _warehouse;

        public GetWareHouseCommandHandler(IBaseRespository<Warehouse> warehouse)
        {
            _warehouse = warehouse;
        }

        public Task<ApiResult<List<Warehouse>>> Handle(GetWareHouseCommand request, CancellationToken cancellationToken)
        {
            var result = new ApiResult<List<Warehouse>>()
            {
                Code = ApiEnum.Success,
                Msg = "仓库查询成功"
            };
            var listhouse = _warehouse.GetAll();

            result.Data=listhouse.ToList(); 

            return Task.FromResult(result);
        }
    }
}
